1 /* 2 Copyright: Marcelo S. N. Mancini (Hipreme|MrcSnm), 2018 - 2021 3 License: [https://creativecommons.org/licenses/by/4.0/|CC BY-4.0 License]. 4 Authors: Marcelo S. N. Mancini 5 6 Copyright Marcelo S. N. Mancini 2018 - 2021. 7 Distributed under the CC BY-4.0 License. 8 (See accompanying file LICENSE.txt or copy at 9 https://creativecommons.org/licenses/by/4.0/ 10 */ 11 12 module hip.api.data.image; 13 14 public interface IImageBase 15 { 16 uint getWidth() const; 17 uint getHeight() const; 18 const(ubyte[]) getPixels() const; 19 ubyte getBytesPerPixel() const; 20 final ushort getBitsPerPixel() const {return getBytesPerPixel()*8;} 21 final size_t getSizeBytes() const{return getBytesPerPixel * getPixels.length;} 22 const(ubyte[]) getPalette() const; 23 final bool hasPalette() const {return getPalette.length != 0;} 24 } 25 26 public interface IHipImageDecoder : IImageBase 27 { 28 ///Use that for decoding from memory, returns whether data was invalid. 29 bool startDecoding(ubyte[] data, void delegate() onSuccess, void delegate() onFailure); 30 31 static const(ubyte[4]) getPixel(){return cast(ubyte[4])[255,255,255,255];} 32 ///Dispose the pixels 33 void dispose(); 34 } 35 36 37 38 public interface IImage : IImageBase 39 { 40 string getName() const; 41 ///loadRaw assumes that you already have the raw pixels to be put on CPU, so, there's no error checking. 42 void loadRaw(in ubyte[] pixels, int width, int height, ubyte bytesPerPixel); 43 /** 44 * loadMemory expects data to be decoded. This process is not 45 * instant on Web. A decision was made of putting successful and 46 * unsuccessful callbacks for that reason. Prefer using the onError callback 47 * rather than the bool return. 48 */ 49 bool loadFromMemory(ubyte[] data, void delegate(IImage self) onSuccess, void delegate() onFailure); 50 bool hasLoadedData() const; 51 ubyte[] convertPalettizedToRGBA() const; 52 ubyte[] monochromeToRGBA() const; 53 } 54 55 56 57 private __gshared extern(System) IHipImageDecoder function(string path) getDecoderFn; 58 void setImageDecoderProvider(typeof(getDecoderFn) provider) 59 { 60 getDecoderFn = provider; 61 } 62 IHipImageDecoder getDecoder(string path){return getDecoderFn(path);}